# 游戏状态
class GAME_STATUS:
    # GAME_STARTED = 1
    # 进行中
    GAME_RUNNING = 2
    # 暂停
    GAME_PAUSE = 3
    # 失败
    GAME_FINISH = 4
    # 重置
    GAME_RESET = 5


# 移动方向
class GAME_MOVE_DIRECTION:
    MOVE_DIRECTION_LEFT = 1
    MOVE_DIRECTION_RIGHT = 2
    MOVE_DIRECTION_UP = 3
    MOVE_DIRECTION_DOWN = 4


# 移动速度，对应定时器超时事件次数
class GAME_SPEED:
    GAME_SPEED_EASY = 30
    GAME_SPEED_NORMAL = 20
    GAME_SPEED_MEDIUM = 10
    GAME_SPEED_HARD = 5


# 全局游戏参数
class MyParam:
    def __init__(self):
        # 定时器超时时间ms
        self.timerMs = 10
        # 定时器超时次数
        self.timerCount = 0
        # snake移动速度
        self.gameSpeed = GAME_SPEED.GAME_SPEED_EASY
        # self.cols = 45
        # self.rows = 67
        # 方格行数, y
        self.cols = 24
        # 方格列数，x
        self.rows = 32
        # 方格大小
        self.blockWidth = 20
        # 游戏状态
        self.gameStatus = GAME_STATUS.GAME_RUNNING
        # 按键方向
        self.keyDirection = GAME_MOVE_DIRECTION.MOVE_DIRECTION_RIGHT
        # 最终移动方向
        self.moveDirection = GAME_MOVE_DIRECTION.MOVE_DIRECTION_RIGHT

    class Builder:
        def __init__(self):
            self.myParam = MyParam()

        # 设置定时器超时参数
        def setTimerMs(self, timerMs):
            self.myParam.timerMs = timerMs
            return self

        # 设置游戏状态
        def setGameStatus(self, gameStatus):
            self.myParam.gameStatus = gameStatus
            return self

        # 返回参数对象
        def build(self):
            return self.myParam


# snake节点
class SnakeNode:

    def __init__(self, row, col, blockWidth, color):
        self.row = row
        self.col = col
        self.blockWidth = blockWidth
        self.x1 = blockWidth * row + (row - 1) * 4
        self.y1 = blockWidth * col + (col - 1) * 4
        self.color = color

    def __str__(self):
        return f"row: {self.row}, col: {self.col}, x1: {self.x1}, y1: {self.y1}, blockWidth: {self.blockWidth}"
